package com.itheima;

import com.baomidou.mybatisplus.annotation.TableId;
import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;
import java.util.Optional;
import java.util.UUID;
import org.junit.jupiter.api.Test;

public class uploadText1 {

    @Test
    public void test1(){

        String ss = "asdascasc.jpg";
        String aa = "asdascasda.png";


        //截取后缀名
        String _ssname = ss.substring(ss.lastIndexOf("."));
        String _aaname = aa.substring(aa.lastIndexOf("."));

        //使用UUID产生随机名称
        String ssname = UUID.randomUUID().toString() + _ssname;
        String aaname = UUID.randomUUID().toString() + _aaname;

        System.out.println(ssname);
        System.out.println(aaname);
    }

    @Test
    public void isnull(){
        //Optional类非空判断使用
        String at = "菜";
        Optional<String> at1 = Optional.ofNullable(at);
        System.out.println(at1);

        boolean present = at1.isPresent();
        System.out.println(present);

    }

    @Test
    public void testRandom(){

        try {

            for (int i = 1; i <= 10; i++) {
                int sha1PRNG = SecureRandom.getInstance("SHA1PRNG").nextInt(5);
                System.out.println(sha1PRNG);
            }

        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        }
    }

    @Test
    public void testSecureRandom(){

        for (int i = 0; i < 10; i++) {
            int index = new SecureRandom().nextInt(5);
            System.out.println(index);
        }
    }
}

